package priv.bestbeat.cloud.api.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import priv.bestbeat.cloud.api.gateway.filters.JWTGlobalFilter;

/**
 * api 网关应用
 * @author 张渠钦
 * @date 2021/12/7 11:17
 */
@SpringBootApplication
public class APIGatewayApplication {

    public static void main(String[] args) {
        SpringApplication.run(APIGatewayApplication.class,args);
    }

    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("user-user",r -> r.path("/termite/user/**")
                        .filters(filterSpec -> filterSpec.rewritePath("/termite/?(?<segment>.*)", "/${segment}"))
                        .uri("http://localhost:7001/"))
                .build();
    }

    @Bean
    public JWTGlobalFilter jwtGlobalFilter() {
        return new JWTGlobalFilter("/**");
    }

}
